import React, { useState } from 'react';
import { Button, Space } from 'antd';

const SonFun = (props) => {
    const { fatherFun, fatherGetFun } = props;
    const [sonDate, setSonDate] = useState({
        sonMsg1: 123,
        sonMsg2: '默认值'
    })
    const handerGetFatherFun = () => {
        fatherFun()
    }

    const handerSetFatherFun = () => {
        let newDta = {
            sonMsg1: 789,
            sonMsg2: '子模块里的内容'
        }
        setSonDate(newDta)
        fatherGetFun(newDta)
    }

    return (
        <>
            <h3>子方法调用父方法，子参数传给父方法</h3>
            <h3>子方法</h3>
            <Space wrap>
                <Button type="primary" onClick={handerGetFatherFun} >调用父模块的函数</Button>
                <Button type="primary" onClick={handerSetFatherFun}>把值传给父模块</Button>
            </Space>
            <h4>sonMsg1：{sonDate.sonMsg1}</h4>
            <h4>sonMsg1：{sonDate.sonMsg2}</h4>
        </>
    )
}

export default SonFun